/**
 * Belongs to WEF
 */
 
var IS_FROM_SELECT = {};

var ButtonTagUtils = {
	showMenu : function(li){
		li.getElementsByTagName('ul')[0].className='ul';
	},
	
	showSubUl : function(li){
		li.getElementsByTagName('ul')[0].className='subUl';
	},
	
	hideMenu : function(ul){
		ul.className='ul_hide';
	},
	
	////内置按钮图片的设置
	showImg : function(name,type){
		var imgId=name+'_img';
		var img=document.getElementById(imgId);
		if(img){
			img.src=App.ctx+'/images/ctrl/button/'+type+'.png';
		}
	},
	
	handleMouseOut : function(a,nav){
		var li=a.parentNode;
		var type='z-index';
		if(document.all)
			type='zIndex';	
		var interval=setTimeout(function(){
			if($(li).css(type)=='400'){		
			}else{
				if(a.className=='top_link' || a.className=='fly'){
					li.getElementsByTagName('ul')[0].className='ul_hide';
				}else{				
				}
				var rootLi=document.getElementById(nav).getElementsByTagName('li')[0];
					if($(rootLi).css(type)=='400'){
					}else{
						var uls=document.getElementById(nav).getElementsByTagName('ul');
						for(var i=0;i<uls.length;i++){
							uls[i].className='ul_hide';
						}
					}
				var grandfather=li.parentNode.parentNode;
				if($(grandfather).css(type)=='400'){}else{
					uls=grandfather.getElementsByTagName('ul');
					for(var i=0;i<uls.length;i++){
						if(uls[i].id!=nav)
							uls[i].className='ul_hide';
					}
				}
			}
		},100);
	},
		
	buildMenuOnIe : function(param){
		if(document.all){
			$(document).ready(function(){ButtonTagUtils.handleHover(param)});
		}
	},
	
	handleHover : function(nav){
		var cssRule;
		var newSelector;
		for (var i = 0; i < document.styleSheets.length; i++){
			var styleSheet=document.styleSheets[i];
			var start=styleSheet.href.lastIndexOf('/')+1;
			var cssName=styleSheet.href.substring(start);
			if(cssName=='menuButton.css')
			{
				for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
				{
					cssRule = document.styleSheets[i].rules[x];
					if (cssRule.selectorText.indexOf("LI:hover") != -1)
					{
						newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
						document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
					}
				}
			}
		}
		var getElm = document.getElementById(nav).getElementsByTagName("LI");
		for (var i=0; i<getElm.length; i++) {
			getElm[i].onmouseover=function() {
				this.className+=" iehover";
			}
			getElm[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" iehover\\b"), "");
			}
		}
	},
	
	handleClick : function(strHref,strTarget){
		if(strTarget!='' && strTarget != 'null'){
			if(window.strTarget){
				window.strTarget.location.href = strHref;
			} else if(window.frames[strTarget]){
				window.frames[strTarget].location.href = strHref;
			} else if(window.parent.strTarget){
				window.parent.strTarget.location.href = strHref;
			} else if(window.parent.frames[strTarget]){
				window.parent.frames[strTarget].location.href = strHref;
			}
		}else{
			window.location.href = strHref;
		}
	}
};
	
var TextTagUtils = {
	registerExp:function(regExp, regText, object, regType){
		var regEx;
		/* 
		 * Email 格式验证正则表达式
		 */
		if(regType == "email")
			regEx = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i;
		/*
		 *  支持手机号码，3-4位区号，7-8位直播号码，1-4位分机号 
		 */
		else if(regType == "phoneNumber")
			regEx = /(^(\d{11})$)|(^(\d{6,8})$)|(^((\d{4}|\d{3})-(\d{6,8}))$)|(^((\d{4}|\d{3})-(\d{6,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)|(^((\d{6,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/;
		else
			regEx = new RegExp(regExp);
		var message = regText == null ? i18n.msg.validateError : regText;
		if(object.value.length > 0 && !regEx.test(object.value)){
			alert(CommonUtils.getMessage(message));
			object.value='';
			object.focus();
		}
	},
	trimBegin:function(object){
		if (/(^[\s]+)/g.test(object.value)) { 
			object.value=(object.value).replace(/(^[\s]*)/g,'');
		}
	},
	trimEnd:function(object){
		if (/([\s]+$)/g.test(object.value)) { 
			object.value=(object.value).replace(/([\s]*$)/g,'');
		}
	},
	trimBoth:function(object){
		if (/(^[\s]+)|([\s]+$)/g.test(object.value)) {
			object.value=(object.value).replace(/(^[\s]*)|([\s]*$)/g,'');
		}
	},
	validateNumber:function(intPart, decPart, message, object){
		var regEx= "^[-+]?\\d{0," + intPart;
		if (decPart == "0") {
			regEx += "}(\\.\\d{0,";
		}else{
			regEx += "}(\\.\\d{1,";
		}
		regEx = regEx + decPart + "})?$";
		var reg = new RegExp(regEx);
		if(object.value != "" && !reg.test(object.value.replace(/,/g, ''))){
			alert(CommonUtils.getMessage(message));
			object.focus();
		}
	}
};

var DateTagUtils = {
	/**
	 * 比较时间，如果Id为strFromDatePickerId的日期选择框的值大于Id为strToDatePickerId的日期选择框的值，则提示strError
	 */
	compareFromToDate : function(strFromDatePickerId, strToDatePickerId, strError, strCurrentDatePickerId) {
		var d1 = new Date(document.getElementById(strFromDatePickerId).value.replace(/-/g, "/"));
		var d2 = new Date(document.getElementById(strToDatePickerId).value.replace(/-/g, "/"));
		if (d2 < d1) {
			alert(strError);
			document.getElementById(strCurrentDatePickerId).value = '';
		}
	},
	toggleDateFormatPrompt : function (labelId , flag){
		if(flag)
			$("#"+labelId).attr("class","prompt");
		else
			$("#"+labelId).attr("class","unprompt");
	},
	// 失去焦点时将时间追加到当日23时59分59秒，updated by filipo 20100727
	addfiftyNineTime : function (hiddenDateTagId, displayDateTagId){
		var hiddenDateTagObj = document.getElementById(hiddenDateTagId);
		var displayDateTagObj = document.getElementById(displayDateTagId);
		if(displayDateTagObj.value == ''){
			hiddenDateTagObj.value = '';
		}else{
			hiddenDateTagObj.value = displayDateTagObj.value + ' 23:59:59';
		}
	}
};

var TextAreaTagUtils = {
	handleMaxLength : function(field, maxlimit) {
		var j = field.value.len();
		if (j > maxlimit) {
			var tt = "";
			var tempString = field.value;
			for (var i = 0; i < maxlimit; i++) {
				if (tt.len() < maxlimit)
					tt = tempString.substr(0, i + 1);
				else
					break;
			}
			if (tt.len() > maxlimit)
				tt = tt.substr(0, tt.length - 1);
			field.value = tt;
			delete tempString;
			delete tt;
		}
	},
	/**
	 * TextArea 标签长度限制.
	 */
	handleKeyPress : function(value, maxLength, event) {
		var key = event.keyCode || event.which;
		// all keys including return.
		if (key >= 47 || key == 13) {
			var length = value.length;
			if (length >= maxLength) {
				try {
					event.returnValue = false;
					event.preventDefault();
				} catch (ex) {

				}
			}
		}
	},
	trimBegin:function(domObj){
		if (/(^[\s]+)/g.test(domObj.value)) { 
			domObj.value=(domObj.value).replace(/(^[\s]*)/g,'');
		}
	},
	trimEnd:function(domObj){
		if (/([\s]+$)/g.test(domObj.value)) { 
			domObj.value=(domObj.value).replace(/([\s]*$)/g,'');
		}
	},	
	trimBoth : function(domObj){
		if (/(^[\s]+)|([\s]+$)/g.test(domObj.value)) {
			domObj.value = (domObj.value).replace(/(^[\s]*)|([\s]*$)/g, '');
		}		
	},
	toUpperCase : function(domObj){
		domObj.value = (domObj.value).toUpperCase();		
	},
	applyConfig : function(targetObj, obj) {
		if (targetObj && obj && typeof obj == 'object') {
			for (var o in obj) {
				targetObj[o] = obj[o];
			}
		}
		return targetObj;
	},
	showFckEditor : function(textAreaId, config) {
		var oFCKeditor = new FCKeditor(textAreaId);
		if (config) {
			if (!config.BasePath) {
				config.BasePath = App.ctx + '/scripts/widgets/fckeditor/';
			}
			if (!config.ToolbarSet) {
				config.ToolbarSet = 'Default';
			}
		}
		this.applyConfig(oFCKeditor, config);
		oFCKeditor.ReplaceTextarea();
	}	
};

var RadioTagUtils = {
	showButton : function(divImgId) {
		var divImg = document.getElementById(divImgId);
		if (divImg) {
			divImg.style.display = 'none';

			var divBtnId = divImgId.substring(0, divImgId.lastIndexOf('_'))
					+ '_buttondiv';
			var divBtn = document.getElementById(divBtnId);
			divBtn.style.display = 'block';
		}

	},
	showImg : function(divBtnId) {
		var divBtn = document.getElementById(divBtnId);
		if (divBtn) {
			divBtn.style.display = 'none';

			var divImgId = divBtnId.substring(0, divBtnId.lastIndexOf('_'))
					+ '_imgdiv';
			var divImg = document.getElementById(divImgId);
			divImg.style.display = 'block';
		}
	},
	changeGenderImg : function(name, value) {
		var imgId = name + '_img';
		var img = document.getElementById(imgId);
		if (img) {
			switch (value) {
				case '1' :
					img.src = App.ctx + '/images/ctrl/radio/male.png';
					break;
				case '0' :
					img.src = App.ctx + '/images/ctrl/radio/female.png';
					break;
			}
		}
		var divBtnId = name + '_buttondiv';
		RadioTagUtils.showImg(divBtnId);
	}
};

var ListTagUtils={
		allOption:[],
		flag:false,
		showItemSel:function(valueFrom, textId, collection, delimiter, title, unselectItemTitle, selectItemTitle){//创建list弹出框
			delimiter=(delimiter==null||delimiter==''||delimiter=='null'||delimiter=='NULL')?',':delimiter;
			var objWindow = {};
			var typeValues;
			objWindow.selOption=[];
			objWindow.allOption=[];
			objWindow.titleText=title;
			objWindow.valueFrom=valueFrom;
			objWindow.unselectItemTitle = unselectItemTitle;
			objWindow.selectItemTitle = selectItemTitle;
			typeValues=document.getElementById(textId).value.split(delimiter);
			collection=collection.substring(1,collection.length-1);
			var array=collection.split('],[');
			for(var i=0;i<array.length;i++){
				var temp=array[i].split(',');
				objWindow.allOption[i]={value:temp[0],textValue:temp[1]};
			}
			if(typeValues[0]!=''){
				for(var j=0;j<typeValues.length;j++){
					objWindow.selOption[objWindow.selOption.length]={value:typeValues[j],textValue:typeValues[j]};
				}
			}
			var returnValue = window.showModalDialog(App.ctx+'/pages/common/listSelector.jsp', objWindow, 
					'dialogWidth:410px;dialogHeight:350px;status:no;');
			var textValues ='';
			var values ='';
			if(returnValue){
				for(var i=0;i<returnValue.length;i++){
					textValues=textValues+returnValue[i].textValue;
					values=values+returnValue[i].value;
					if(i!=returnValue.length-1){
						textValues=textValues+delimiter;
						values=values+delimiter;
					}						
				}
			}
			document.getElementById(textId).value=textValues;
			document.getElementById(textId).blur();	
		},
		init:function(){
			var selOption= [];
			if(window.showModalDialog==null){
				ListTagUtils.allOption = window.opener.objWindow.allOption;
				selOption = window.opener.objWindow.selOption;
				document.getElementById("titleId").innerHTML=window.opener.objWindow.titleText;
			}else{
				ListTagUtils.allOption = window.dialogArguments.allOption;
				selOption = window.dialogArguments.selOption;
				document.getElementById("titleId").innerHTML=window.dialogArguments.titleText;
			}
			var opeOption =[];
			for(var i=0;i<ListTagUtils.allOption.length;i++){
				var bool = false; 
				for(var j=0;j<selOption.length;j++){
					if(ListTagUtils.allOption[i].textValue==selOption[j].textValue){
						selOption[j].value=ListTagUtils.allOption[i].value;
						bool = true;
						break;
					}
				}
				if(!bool)
					opeOption[opeOption.length] = ListTagUtils.allOption[i];
			}
			var valueFrom='right';
			if(window.showModalDialog==null){
				valueFrom=window.opener.objWindow.valueFrom;
			}else{
				valueFrom=window.dialogArguments.valueFrom;
			}
			if(valueFrom=='left'){
				document.getElementById("leftList").innerHTML=window.dialogArguments.selectItemTitle;
				document.getElementById("rightList").innerHTML=window.dialogArguments.unselectItemTitle;
				DWRUtil.addOptions("typeNoSelId", selOption, 'value', 'textValue');
				DWRUtil.addOptions("typeSelId", opeOption, 'value', 'textValue');
			}else{
				document.getElementById("leftList").innerHTML=window.dialogArguments.unselectItemTitle;
				document.getElementById("rightList").innerHTML=window.dialogArguments.selectItemTitle;
				DWRUtil.addOptions("typeNoSelId", opeOption, 'value', 'textValue');
				DWRUtil.addOptions("typeSelId", selOption, 'value', 'textValue');
			}
		},
		add:function()
		{
			var f = document.form1;
			var num=0;
			var length=f.s1.options.length;
			for(var i=0;i<length;i++){
				if(f.s1[i-num].selected){
					selectid = f.s1[i-num].index;
					num++;
				 	if ((selectid)==-1)
				 	{
				 		window.alert(i18n.list.plSelectMsg);
				 		return;
				 	} 
				 	for(var k=0;k<f.s2.options.length;k++)
				 	{  
				     	if (f.s2.options[k].value==f.s1.value )
				     	{
				      		window.alert(i18n.list.exitedMsg);
				     	 	return;
				    	}
				 	}
				 	text=f.s1[selectid].value;
				  	var obj = new Option(f.s1[selectid].innerHTML,text);
				  	f.s2.options.add(obj);
				  	f.s1.remove(selectid);
				}
			 }
		},
		remove:function(id)
		{
			 var f = document.form1;
			 if(id=="s2")
			 {
				var length=f.s2.options.length;
				var num=0;
				for(var i=0;i<length;i++){
					if(f.s2[i-num].selected){
						selectid = f.s2[i-num].index;
						num++;
						if ((selectid)==-1)
						{
							window.alert(i18n.list.removeMsg);
							return;
						}
						var o=new Option(f.s2[selectid].innerHTML,f.s2[selectid].value);
						f.s1.options.add(o);
				    	f.s2.remove(selectid);
					}
				}
			 }else
			 {
				if ((f.s1.selectedIndex)==-1)
				{
					window.alert(i18n.list.removeMsg);
					return;
				}
				val = f.s1.value;
				f.s1.options.remove(f.s1.selectedIndex); 
				for(var i = 0;i < f.s2.length; i++)
				{
					if(f.s2[i].value == val) 
					{
						f.s2.remove(i);
						break;
					}
				   }
			}
		},
		selectDoubleClick:function (selectid,type){
			var f = document.form1;
			if(type=='left'){
				var o=new Option(f.s1[selectid].innerHTML,f.s1[selectid].value);
				f.s2.options.add(o);
			    f.s1.remove(selectid);
			}else{
				var o=new Option(f.s2[selectid].innerHTML,f.s2[selectid].value);
				f.s1.options.add(o);
			    f.s2.remove(selectid);
			}
		},
		addAll:function ()
		{
			DWRUtil.removeAllOptions('typeSelId');
			DWRUtil.removeAllOptions('typeNoSelId');
			DWRUtil.addOptions("typeSelId", ListTagUtils.allOption, 'value', 'textValue');
		},
		removeAll:function ()
		{
			DWRUtil.removeAllOptions('typeSelId');
			DWRUtil.removeAllOptions('typeNoSelId');
			DWRUtil.addOptions("typeNoSelId", ListTagUtils.allOption, 'value', 'textValue');
		},	
		submitClose:function (){
			ListTagUtils.flag=true;
			 window.close();
		},
		beforeCloseWindow:function (){
			var f = document.form1;
			var opeOption =[];
			if(ListTagUtils.flag){
				var valueFrom='right';
				if(window.showModalDialog==null){
					valueFrom=window.opener.objWindow.valueFrom;
				}else{
					valueFrom=window.dialogArguments.valueFrom;
				}
				if(valueFrom=='left'){
					for(var k=0;k<f.s1.options.length;k++){  
			 			opeOption[opeOption.length] = {value:f.s1.options[k].value,textValue:f.s1.options[k].innerHTML};
			 		}
				}else{
					for(var k=0;k<f.s2.options.length;k++){  
			 			opeOption[opeOption.length] = {value:f.s2.options[k].value,textValue:f.s2.options[k].innerHTML};
			 		}
				}	
			}else{
				opeOption=window.dialogArguments.selOption||window.opener.objWindow.selOption;
			}
			if(window.showModalDialog){
			 	 window.returnValue = opeOption;
			}
		}
};

	var inputsDatacheckedForm;
	var textareasDatacheckedForm;
	var selectsDatacheckedForm;
	var status;
	var FormTagUtils={
		compareInputInit:function(formId){
			$(document).ready(function(){
				FormTagUtils.initFileds(formId);
			});
			window.onbeforeunload = function(){			
				if(FormTagUtils.checkModification(formId)){
					return i18n.form.modifiedMsg;
				}
			};
			window.onunload = function(){
				delete window.parent.IS_DIRTY_FUNC[window.parent.ACTIVE_TAB_ID];
			};
			window.parent.IS_DIRTY_FUNC[window.parent.ACTIVE_TAB_ID] = function(){
				if(FormTagUtils.checkModification(formId)){
					return true;
				}
				return false;
			};
		},
		initFileds:function(formId) {
			inputsDatacheckedForm = null;
			textareasDatacheckedForm = null;
			selectsDatacheckedForm = null;
			var inputs = $("#"+formId+" :input");
			var textareas = $("#"+formId+" :textarea");
			var selects = $("#"+formId+" :select");	
			inputsDatacheckedForm = new Array(inputs.length);
			for (var i = 0; i < inputs.length; i++) {
				
				if(inputs[i].type == "checkbox"){
					inputsDatacheckedForm[i] = inputs[i].checked;
				}
				else if (inputs[i].type == "radio") {
					inputsDatacheckedForm[i] = inputs[i].checked;
				}
				else if(inputs[i].type == "text"){
					inputsDatacheckedForm[i] = inputs[i].value;
				}
			}
			textareasDatacheckedForm = new Array(textareas.length);
			for (var i = 0; i < textareas.length; i++) {
				textareasDatacheckedForm[i] = textareas[i].value;
			}
			selectsDatacheckedForm = new Array(selects.length);
			for (var i = 0; i < selects.length; i++) {
				selectsDatacheckedForm[i] = selects[i].value;
			}
		},
		/*		
		 * 判断表单中值是否被修改了
		 */
		checkModification:function (formId) {
			var inputs = $("#"+formId+" :input");
			var textareas = $("#"+formId+" :textarea");
			var selects = $("#"+formId+" :select");
			var hasBeenChanged = false;
			for (var i = 0; i < inputs.length; i++) {
				if (inputs[i].type == "radio" && inputsDatacheckedForm[i] != undefined
						&& (inputs[i].checked != inputsDatacheckedForm[i])) {
					hasBeenChanged = true;
					break;
				}
				else if (inputs[i].type == "checkbox" && inputsDatacheckedForm[i] != undefined
						&& (inputs[i].checked != inputsDatacheckedForm[i])) {
					hasBeenChanged = true;
					break;
				}
				else if(inputs[i].type == "text" && inputsDatacheckedForm[i] != undefined
						&& (inputs[i].value != inputsDatacheckedForm[i])){
					hasBeenChanged = true;
					break;	
				}
			}
			if(!hasBeenChanged){
				for (var i = 0; i < textareas.length; i++) {
					if (textareasDatacheckedForm[i] != undefined && textareasDatacheckedForm[i] != textareas[i].value) {
						hasBeenChanged = true;
						break;
					}
				}
			}
			if(!hasBeenChanged){
				for (var i = 0; i < selects.length; i++) {
					if (selectsDatacheckedForm[i] != undefined && selectsDatacheckedForm[i] != selects[i].value) {
						hasBeenChanged = true;
						break;
					}
				}
			}
			return hasBeenChanged;
		},
		saveFormData:function (formId){
			status=true;
			$('#'+formId).submit()
		}
};
var ComboxTagUtils = {
		getCodeAndName : function(entityClassName, codeField, nameField, domObj) {
			var valueFieldName = domObj.name.substring(0, domObj.name
							.indexOf('_code_name_display'));
			/*if ((entityClassName == null || entityClassName == undefined
					|| entityClassName == '' || entityClassName == 'null')
					|| (codeField == null || codeField == undefined
							|| codeField == '' || codeField == 'null')
					|| (nameField == null || nameField == undefined
							|| nameField == '' || nameField == 'null')) {
				$("input[name='" + valueFieldName + "']").val(domObj.value);
				return;
			}
			if ((domObj.value == null || domObj.value == undefined || domObj.value == '')) {
				$("input[name='" + valueFieldName + "']").val('');
				return;
			}*/
			//$("input[name='" + valueFieldName + "']").val(domObj.value);
			/*
			// 取得CODE value
			var value;
			if (domObj.value && domObj.value.indexOf('/') != -1) {
				var astrValue = domObj.value.split('/');
				value = astrValue[0];
			} else {
				value = domObj.value;
			}
			CommonWebService.loadByPk(entityClassName, codeField, value, {
				callback : function(result) {
					if (result) {
						domObj.value = result[codeField] + '/' + result[nameField];
						if (domObj.name
								&& domObj.name.indexOf('_code_name_display') != -1) {
							$("input[name='" + valueFieldName + "']")
									.val(result[codeField]);
						}
					} else {
						$("input[name='" + valueFieldName + "']").val(domObj.value);
						alert('Code does not exist!');
					}
				},
				errorHandler : function(errorString, exception) {
					$("input[name='" + valueFieldName + "']").val(domObj.value);
					alert('Code does not exist!');
				},
				async : false
			});*/
		},
		getValueByInputName : function(name) {
			var value = $("input[name='" + name + "']").val();
			if (value) {
				return value;
			}
			return '';
		},
		clearTextValue:function(obj,displayObj){
			if( (displayObj.value == '' || displayObj.value == null) && obj){
				obj.value = '';
			}else{
				obj.value = displayObj.value;
			}
		}	
	};	
var EcTableTagUtils={
		ecTableInit:function(tableColumnId,tableEnterId){
			$(document).ready(function(){
				EcTableTagUtils.setColumnWidth(tableColumnId);
				EcTableTagUtils.rapidPaging(tableEnterId);
			});
			$(window).bind('resize',function(){
				EcTableTagUtils.setColumnWidth(tableColumnId);
			});
		},
		userCompactViewEcTableInit:function(tableEnterId){
			$(document).ready(function(){
				EcTableTagUtils.rapidPaging(tableEnterId);
			});
		},
		leftToolBarEctableInit:function(tableId){
			$(document).ready(function(){
				//TableUtils._bindECTableClick({tableId:tableId});
				EcTableTagUtils.rapidPaging(tableId);
			});
		},
		setColumnWidth:function(tableId){	
			var hiddenHeadTable=document.getElementById(tableId+'_hd');
			var headTable=document.getElementById(tableId);
			var calcTable=document.getElementById(tableId+"_calc");
			var widthArr=[];
			if(headTable){
				headTable.getElementsByTagName('thead')[0].style.display='';
				hiddenHeadTable.getElementsByTagName('thead')[0].style.display='none';
				var headRow=headTable.getElementsByTagName('thead')[0].rows[0];
				var hiddenRow=hiddenHeadTable.getElementsByTagName('thead')[0].rows[1];
				var bodyRow=headTable.getElementsByTagName('tbody')[0].rows[0];
				var calcRow=calcTable.getElementsByTagName('tbody')[0].rows[0];
				if(!headRow || !bodyRow){
					return false;
				}
				
				var length=headRow.cells.length;
				for(var i=0;i<length;i++){
					widthArr[i]=headRow.cells[i].offsetWidth-7;
					if(i==length-1)
						widthArr[i]='';
				}
				headTable.getElementsByTagName('thead')[0].style.display='none';
				hiddenHeadTable.getElementsByTagName('thead')[0].style.display='';
				for(var i=0;i<length;i++){
					bodyRow.cells[i].width=widthArr[i];
					hiddenRow.cells[i].width=widthArr[i];
					if(calcRow)
					{
						calcRow.cells[i].width=widthArr[i];
					}
				}
			}
		},
		rapidPaging:function(table_id){
			var a_id=table_id+"_a_id";
			var input_id=table_id+"_input_id";
			var inputObj=document.getElementById(input_id);
			if(inputObj){
				inputObj.onkeyup=function(event){
					var e=event || window.event;
					if(e.keyCode==13){
						eval(decodeURI(document.getElementById(a_id).href));
					}
				}
				inputObj.onkeypress=function(event){
					var e = event || window.event;
					return CommonUtils.checkNumberTextInput(e, this, false, 3, 0);
				}
			}
		}
};

/**
 * Tab相关变量与方法
 */
var OPENED_TABS_ID = [];
var ORIGINAL_TAB_ID = null;
var ACTIVE_TAB_ID = null;
var IS_DIRTY_FUNC = {};
Array.prototype.indexOf = function(o) {
	for (var i = 0; i < this.length; i++)
		if (this[i] == o)
			return i;
	return -1;
}

Array.prototype.contains = function(o) {
	for (var i = 0; i < this.length; i++)
		if (this[i] == o)
			return true;
	return false;
}

Array.prototype.del = function(n) {
	if (n < 0)
		return this;
	return this.slice(0, n).concat(this.slice(n + 1, this.length));
}
String.prototype.sub = function(n) {
	var r = /[^\x00-\xff]/g;
	if (this.replace(r, "mm").length <= n)
		return this;
	var m = Math.floor(n / 2);
	for (var i = m; i < this.length; i++) {
		if (this.substr(0, i).replace(r, "mm").length >= n) {
			return this.substr(0, i);
		}
	}
	return this;
};
String.prototype.len = function() {
	return this.replace(/[^\x00-\xff]/g, "**").length;
};
var TabTagUtils = {
	newTab : function(menuId, menuName, menuURL, closeAble, validate) {
		
		if (OPENED_TABS_ID.contains(menuId)) {
			var event = {
				data : {
					tabId : menuId
				}
			};
			TabTagUtils.showTab(event);
			return;
		}
		
		if (OPENED_TABS_ID.length >= 7) {
			var msgTooManyTbs = '';			
				msgTooManyTbs = i18n.tab.msgTooManyTabs;			
				alert(msgTooManyTbs);
			return 'TABOVER';
		}
		
		var oDivTab = document.getElementById('divTab');
		var divNewTab = document.createElement('div');
		divNewTab.id = menuId;
		$(divNewTab).attr('class', 'tab-title-up ui-state-active');
		$(divNewTab).attr('style', 'display:block;');

		var divLeft = document.createElement('div');
		divLeft.innerHTML = '&nbsp;';
		$(divLeft).attr('class', 'tab-title-left');

		var divCenter = document.createElement('div');
		var shortMenuName = menuName.sub(10);
		if (shortMenuName != menuName) {
			shortMenuName += '...';
		}
		divCenter.innerHTML = shortMenuName;
		$(divCenter).attr('class', 'tab-title-center');
		$(divCenter).attr('title', menuName);
		$(divCenter).bind('click', {
					tabId : menuId
				}, TabTagUtils.showTab);

		var divRight = document.createElement('div');
		divRight.innerHTML = '&nbsp;';
		$(divRight).attr('class', 'tab-title-right');

		divNewTab.appendChild(divLeft);
		divNewTab.appendChild(divCenter);
		divNewTab.appendChild(divRight);

		if (!(closeAble == false)) {
			var divClose = document.createElement('div');
			$(divClose).attr('class', 'tab-close ui-icon');
			$(divClose).attr('title', i18n.tab.closeTab);
			$(divClose).bind('click', {
						tabId : menuId,
						validateItem : validate
					}, TabTagUtils.closeTab);
			divNewTab.appendChild(divClose);
		}

		oDivTab.appendChild(divNewTab);
		
		var oDivFrame = $('#divFrame')[0];
		var oNewFrame = document.createElement('iframe');
		var jNewFrame = $(oNewFrame);
			jNewFrame.attr('id', menuId + '_frame');
			jNewFrame.css('display', 'block');		
			jNewFrame.attr('scrolling','auto');
			jNewFrame.css('width', '100%');
			jNewFrame.css('height', '100%');		
			jNewFrame.css('border', '0');
			jNewFrame.css('frameborder', '0');		
		
		oDivFrame.appendChild(oNewFrame);

		// TODO 暂时解决
		if (menuURL.indexOf("?") != -1) {
			menuURL = menuURL + "&random=" + Math.random();
		} else {
			menuURL = menuURL + "?random=" + Math.random();
		}

		var event = {
			data : {
				tabId : menuId,
				src : menuURL
			}
		};

		TabTagUtils.showTab(event);
		
		OPENED_TABS_ID.push(menuId);
	},
	showTab : function(event) {
		var context = event.data;
		var _tabId = context.tabId;
		var _frameId = _tabId + '_frame';
		var _src = context.src;
		
		$('#' + ACTIVE_TAB_ID).attr('class', 'tab-title ui-state-default');
		$('#' + ACTIVE_TAB_ID + '_frame').css('display', 'none');
		
		$('#' + _tabId).attr('class', 'tab-title-up ui-state-active');
		$('#' + _frameId).css('display', 'block');
		
		ORIGINAL_TAB_ID = ACTIVE_TAB_ID;
		ACTIVE_TAB_ID = _tabId;
		if (_src) {
			$('#' + _frameId).attr('src', _src);
		}
		
	},
	closeTab : function(event) {
		var context = event.data;
		var _tabId = context.tabId;
		var _frameId = _tabId + '_frame';

		var currentTab = $('#' + _tabId);
		var currentFrame = $('#' + _frameId);
		try{
			if (TabTagUtils.isDirty(event.data.tabId)) {
				var bln = window.confirm(i18n.tab.msgDataChange);
				if (!bln) {
					return false;
				}
			};
			if(context.validateItem!=undefined){
				var valResult = eval(context.validateItem);
				if(valResult!=undefined&&!valResult){
					return false;
				};
			}
		}catch(e){}
		
		delete IS_DIRTY_FUNC[event.data.tabId];
		
		
		currentTab[0].parentNode.removeChild(currentTab[0]);
		
		currentFrame[0].parentNode.removeChild(currentFrame[0]);
		
		OPENED_TABS_ID = OPENED_TABS_ID.del(OPENED_TABS_ID.indexOf(_tabId));
		
		if (_tabId == ACTIVE_TAB_ID) {
			var originalTabId = null;
			if (ORIGINAL_TAB_ID && OPENED_TABS_ID.contains(ORIGINAL_TAB_ID)) {
				originalTabId = ORIGINAL_TAB_ID;
			} else if (OPENED_TABS_ID.length > 0) {
				originalTabId = OPENED_TABS_ID[OPENED_TABS_ID.length - 1];
			}
			if (originalTabId) {
				var event = {
					data : {
						tabId : originalTabId
					}
				};
				TabTagUtils.showTab(event);
			}
		}
	},
	closeActiveTab : function(){
		if(ACTIVE_TAB_ID){
			var event =  { data : { tabId : ACTIVE_TAB_ID } };
			TabTagUtils.closeTab(event);
		}
	},
	closeActiveTabById : function(_tabId){
		if(_tabId){
			if(OPENED_TABS_ID.indexOf(_tabId)>-1){
				var event =  { data : { tabId : _tabId } };
				TabTagUtils.closeTab(event);
			}
		}
	},
	closeAndNewTab : function(menuId, menuName, menuURL, closeAble, validate) {
		var b = TabTagUtils.closeActiveTabById(menuId);
		if(b == undefined || b === true){
			TabTagUtils.newTab(menuId, menuName, menuURL, closeAble, validate);
		}
	},
	setCwinHeight : function(id) {		
	},
	isDirty : function(currentTabId){
		// 占位符，勿动 GXL
		if(IS_DIRTY_FUNC[currentTabId]){
			return IS_DIRTY_FUNC[currentTabId]();
		}
		return false;
	},
	getOpenTabs : function(){
		return OPENED_TABS_ID;
	}
};
